#!/usr/bin/php
<?php
require_once(dirname(__FILE__) . '/simple_helpers.inc');


/*
 * Grammar tests.
 * Currently this tests whether the rules of the grammar are well formed,
 * i.e. respecting Luminous's internal data formats.
 * 
 * This tests all grammars known to Luminous
 */ 


$grammars = array();
foreach($luminous_grammars->ListGrammars() as $d=>$c)
{
  if (is_array($c))
    $grammars[] = $c[0];
  else
    $grammars[] = $c;
}

$tests = array(
  
  // simple case
  '<&R_24>',
  
  // adjacant cases
  '<&R_24>0123',
  '0123<&R_24>',
  
  '<&R_24>while',
  'while<&R_24>',
  
  '<&R_24>// comment',  
  
  // Enclosed in other types
  '`<&R_24>`',
  '"<&R_24>"',
  "'<&R_24>'",  
  "// <&R_24>\n",
  "/* Comment <&R_24> this */"
  
);

foreach($grammars as $g)
{
  foreach($tests as $t)
  {
    $gr = $luminous_grammars->GetGrammar($g);
    $l = new Luminous();
    $l->pre_escaped = true;
    
    $out = $l->Easy_Parse($t, $gr);
    
    if (strpos($out, '<&R_24>') === false)
      test_fail_output($g, $t, $out, "<&R_24> Not found in output");
  }
}

exit($EXIT_STATUS);